import random

ips1 = "172.25.254."
ips4 = {}
ips5 = []
with open("ips.txt", "w") as f:
    # 生成IP
    for i in range(1200):
        # 获得随机数
        ips2 = random.randint(0, 255)
        ips3 = f"{ips1}{ips2}\n"
        # 在列表里面添加ip
        ips5.append(ips3)
        # 在文档里面写入IP
        f.write(ips3)
    # 去除IPs5里重复的IP
    ips6 = set(ips5)
    # 统计IP出现次数并且放入字典
    for j in ips6:
        d = ips5.count(j)
        ips4[j] = d
    # 给字典排序
    y = sorted(ips4.items(), key=lambda x: x[1])
    # 取最后十个，因为是从小往大排的
    ips7 = y[-1:-11:-1]
    # 输出出现次数前十的IP及次数
    for g,a in ips7:
        print(g,"出现了",a,"次")

